const pkg = require('./package')
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')

module.exports = {
  mode: 'spa',

  /*
  ** Headers of the page
  */
  head: {
    title: '趣创益',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      {
        hid: 'description',
        name: 'description',
        content: '趣创益，少儿教育，少儿编程，wedo2.0，ev3，scratch，机器人编程'
      }
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
  },

  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },

  /*
  ** Global CSS
  */
  css: ['~/assets/style/app.styl'],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: ['@/plugins/vuetify', '@/plugins/axios', '@/plugins/create'],

  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://github.com/nuxt-community/axios-module#usage
    '@nuxtjs/axios',
    '@nuxtjs/auth'
  ],
  /*
  ** Auth module configuration
  */
  auth: {
    strategies: {
      local: {
        endpoints: {
          login: {
            url: '/api/user/login',
            method: 'post',
            propertyName: ''
          },
          logout: { url: '/api/user/logout', method: 'get' },
          user: { url: '/api/user/info', method: 'get', propertyName: '' }
        }
      }
    },
    redirect: {
      login: '/login',
      logout: '/',
      callback: '/login',
      home: '/'
    },
    cookie: {
      prefix: 'QYCSESSION.'
    },
    localStorage: false
  },
  /*
  ** Axios module configuration
  */
  axios: {
    // See https://github.com/nuxt-community/axios-module#options
    baseURL: '/',
    browserBaseURL: '/'
  },
  srcDir: 'src/',
  router: {
    linkActiveClass: 'link-active',
    linkExactActiveClass: 'link-exact-active',
    middleware: ['authed']
  },
  /*
  ** Build configuration
  */
  build: {
    analyze: false,
    transpile: ['vuetify/lib'],
    plugins: [new VuetifyLoaderPlugin()],
    loaders: {
      stylus: {
        import: ['~assets/style/vars.styl']
      }
    },
    /*
    ** You can extend webpack config here
    */
    extend(config, ctx) {
      // Run ESLint on save
      if (ctx.isDev && ctx.isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    },
    extractCSS: true,
    // publicPath: 'https://cdn.jsdelivr.net/gh/cloud-assets/quchuangyi@1.0.2/',
    terser: false,
    filenames: {
      app: ({ isDev }) => (isDev ? 'js/[name].js' : 'js/[name].[chunkhash].js'),
      chunk: ({ isDev }) => (isDev ? 'js/[name].js' : 'js/[chunkhash].js'),
      css: ({ isDev }) => (isDev ? 'css/[name].css' : 'css/[chunkhash].css')
    }
  },
  buildDir: '.nuxt/client'
}
